var express = require('express');
var router = express.Router();
const mysql=require('mysql');
const connection=require('../public/javascripts/mysql');
/* GET home page. */

router.post('/user', function(req, res, next) {
    connection.query('SELECT * FROM userinfo where tel=?', [req.body.id],(error, results, fields) => {
        console.log(results[0].pwd,req.body.pass);
        if (results[0].pwd==req.body.pass){
            res.json([1,results[0].id]);
        }else {
            res.json(2);
        }
        // res.json(results);
    });
});
router.post('/userall', function(req, res, next) {
    connection.query('SELECT * FROM userinfo where id=?', [req.body.id],(error, results, fields) => {
        res.json(results[0]);
    });
});
router.post('/useradd', function(req, res, next) {
    connection.query('SELECT * FROM userinfo where tel=?', [req.body.id],(error, results, fields) => {
        if(results){
            res.json('err');
        }else {
            connection.query('INSERT INTO userinfo SET tel = ?, pwd = ? ', [req.body.id,req.body.pass],(error, results, fields) => {

                res.json(results[0]);
            });
        }

    });





});







module.exports = router;
